<?php

namespace app\common\model\video;

use app\common\utils\Utils;
use think\Model;


class Item extends Model
{

    

    

    // 表名
    protected $name = 'video_item';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'image_text',
        'video_href_text',
        'createtime_text'
    ];

    public function getImageTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image']) ? $data['image'] : '');

        return cdnurl($value, true);
    }
    public function getVideoHrefTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['video_href']) ? $data['video_href'] : '');

        return cdnurl($value, true);
    }
    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');

        return Utils::time_format($value);
    }

    public function videoitem()
    {
        return $this->belongsTo('app\common\model\video\Cate', 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
